#ifndef _PARSER_H_
#define _PARSER_H_

#include <iostream>

using namespace std;

#include "listlexer.h"
#include "token.h"
#include "error.h"

class Parser {
protected:
    ListLexer *input;
    Token *lookahead;
public:
    Parser(ListLexer *input) {
        this->input = input;
        consume();
    }

    void match(int x) {
        if (lookahead->type == x) {
            cout << lookahead->to_string() << endl;
            consume();
        }
        else {
            string s = "expecting ";
            s += input->get_token_name(x);
            s += "; found ";
            s += lookahead->text;
            throw Error(s);
        }
    }

    void consume() {
        lookahead = input->next_token();
    }
};

#endif
